// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   register_ok.java

package design.price_change;

import include.get_sql.getInsertSql;
import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;

public class register_ok extends HttpServlet
{

	public register_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession();
		nseer_db_backup1 design_db = new nseer_db_backup1(dbApplication);
		nseer_db_backup1 design_db1 = new nseer_db_backup1(dbApplication);
		nseer_db_backup1 manufacture_db = new nseer_db_backup1(dbApplication);
		nseer_db_backup1 manufacture_db1 = new nseer_db_backup1(dbApplication);
		ValidataNumber validata = new ValidataNumber();
		getInsertSql getInsertSql = new getInsertSql();
		counter count = new counter(dbApplication);
		try
		{
			if (design_db.conn((String)dbSession.getAttribute("unit_db_name")) && design_db1.conn((String)dbSession.getAttribute("unit_db_name")) && manufacture_db.conn((String)dbSession.getAttribute("unit_db_name")) && manufacture_db1.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String product_ID = request.getParameter("product_ID");
				String list_price2 = request.getParameter("list_price");
				StringTokenizer tokenTO4 = new StringTokenizer(list_price2, ",");
				String list_price;
				String list_price1;
				for (list_price = ""; tokenTO4.hasMoreTokens(); list_price = (new StringBuilder(String.valueOf(list_price))).append(list_price1).toString())
					list_price1 = tokenTO4.nextToken();

				String cost_price2 = request.getParameter("cost_price");
				StringTokenizer tokenTO5 = new StringTokenizer(cost_price2, ",");
				String cost_price;
				String cost_price1;
				for (cost_price = ""; tokenTO5.hasMoreTokens(); cost_price = (new StringBuilder(String.valueOf(cost_price))).append(cost_price1).toString())
					cost_price1 = tokenTO5.nextToken();

				int n = 0;
				if (!validata.validata(list_price) || Double.parseDouble(list_price) < 0.0D)
					n++;
				if (!validata.validata(cost_price) || Double.parseDouble(cost_price) < 0.0D)
					n++;
				if (n == 0)
				{
					String responsible_person_ID = "";
					String responsible_person_name = "";
					String first_kind = request.getParameter("select1");
					String product_name = request.getParameter("product_name");
					String factory_name = request.getParameter("factory_name");
					String type = request.getParameter("type");
					String product_class = request.getParameter("product_class");
					String product_nick = request.getParameter("product_nick");
					String twin_name = request.getParameter("twin_name");
					String twin_ID = request.getParameter("twin_ID");
					String personal_unit = request.getParameter("personal_unit");
					String personal_value = request.getParameter("personal_value");
					String warranty = request.getParameter("warranty");
					String lifecycle = request.getParameter("lifecycle");
					String amount_unit = request.getParameter("amount_unit");
					String register = request.getParameter("register");
					String bodya = new String(request.getParameter("product_describe").getBytes("UTF-8"), "UTF-8");
					String product_describe = exchange.toHtml(bodya);
					String changer_ID = request.getParameter("changer_ID");
					String changer = request.getParameter("changer");
					String change_time = request.getParameter("change_time");
					String lately_change_time = request.getParameter("lately_change_time");
					String file_change_amount = request.getParameter("file_change_amount");
					int change_amount = Integer.parseInt(file_change_amount) + 1;
					String column_group = getInsertSql.sql((String)dbSession.getAttribute("unit_db_name"), "design_file");
					try
					{
						String sqloo = (new StringBuilder("select * from design_file where product_ID='")).append(product_ID).append("'").toString();
						ResultSet rsoo = design_db.executeQuery(sqloo);
						if (rsoo.next())
						{
							String sqll = (new StringBuilder("insert into design_file_dig(chain_id,chain_name,PRODUCT_ID,PRODUCT_NAME,PRODUCT_NICK,PRODUCT_CLASS,TYPE,AMOUNT_UNIT,PRODUCT_DESCRIBE,FACTORY_NAME,FACTORY_ID,PROVIDER_GROUP,PHOTO1,PHOTO2,WARRANTY,LIST_PRICE,COST_PRICE,REAL_COST_PRICE,LIFECYCLE,PERSONAL_UNIT,PERSONAL_VALUE,TWIN_NAME,TWIN_ID,REMARK,CHECK_TAG,ACHIEVEMENT_SUM,ATTACHMENT_NAME,RETURN_SUM,RETURN_AMOUNT,FILE_CHANGE_AMOUNT,USED_PRODUCT_NAME,RESPONSIBLE_PERSON_NAME,RESPONSIBLE_PERSON_ID,REGISTER,CHECKER,CHANGER,REGISTER_ID,CHECKER_ID,CHANGER_ID,REGISTER_TIME,CHECK_TIME,CHANGE_TIME,LATELY_CHANGE_TIME,LATELY_TRADE_TIME,DELETE_TIME,RECOVERY_TIME,MODIFY_TAG,EXCEL_TAG,EXCEL_TAG2,EXCEL_TAG3,EXCEL_TAG4,DESIGN_MODULE_TAG,DESIGN_PROCEDURE_TAG,DESIGN_CELL_TAG,RECOMMEND_PROVIDER_TAG,PRICE_CHANGE_TAG,PRICE_ALARM_TAG,promotion,opinion,promotion2,opinion2,promotion3,opinion3,promotion4,opinion4) values('")).append(rsoo.getString("chain_id")).append("','").append(rsoo.getString("chain_name")).append("','").append(rsoo.getString("PRODUCT_ID")).append("','").append(rsoo.getString("PRODUCT_NAME")).append("','").append(rsoo.getString("PRODUCT_NICK")).append("','").append(rsoo.getString("PRODUCT_CLASS")).append("','").append(rsoo.getString("TYPE")).append("','").append(rsoo.getString("AMOUNT_UNIT")).append("','").append(rsoo.getString("PRODUCT_DESCRIBE")).append("','").append(rsoo.getString("FACTORY_NAME")).append("','").append(rsoo.getString("FACTORY_ID")).append("','").append(rsoo.getString("PROVIDER_GROUP")).append("','").append(rsoo.getString("PHOTO1")).append("','").append(rsoo.getString("PHOTO2")).append("','").append(rsoo.getString("WARRANTY")).append("','").append(rsoo.getString("LIST_PRICE")).append("','").append(rsoo.getString("COST_PRICE")).append("','").append(rsoo.getString("REAL_COST_PRICE")).append("','").append(rsoo.getString("LIFECYCLE")).append("','").append(rsoo.getString("PERSONAL_UNIT")).append("','").append(rsoo.getString("PERSONAL_VALUE")).append("','").append(rsoo.getString("TWIN_NAME")).append("','").append(rsoo.getString("TWIN_ID")).append("','").append(rsoo.getString("REMARK")).append("','").append(rsoo.getString("CHECK_TAG")).append("','").append(rsoo.getString("ACHIEVEMENT_SUM")).append("','").append(rsoo.getString("ATTACHMENT_NAME")).append("','").append(rsoo.getString("RETURN_SUM")).append("','").append(rsoo.getString("RETURN_AMOUNT")).append("','").append(rsoo.getString("FILE_CHANGE_AMOUNT")).append("','").append(rsoo.getString("USED_PRODUCT_NAME")).append("','").append(rsoo.getString("RESPONSIBLE_PERSON_NAME")).append("','").append(rsoo.getString("RESPONSIBLE_PERSON_ID")).append("','").append(rsoo.getString("REGISTER")).append("','").append(rsoo.getString("CHECKER")).append("','").append(rsoo.getString("CHANGER")).append("','").append(rsoo.getString("REGISTER_ID")).append("','").append(rsoo.getString("CHECKER_ID")).append("','").append(rsoo.getString("CHANGER_ID")).append("','").append(rsoo.getString("REGISTER_TIME")).append("','").append(rsoo.getString("CHECK_TIME")).append("','").append(rsoo.getString("CHANGE_TIME")).append("','").append(rsoo.getString("LATELY_CHANGE_TIME")).append("','").append(rsoo.getString("LATELY_TRADE_TIME")).append("','").append(rsoo.getString("DELETE_TIME")).append("','").append(rsoo.getString("RECOVERY_TIME")).append("','").append(rsoo.getString("MODIFY_TAG")).append("','").append(rsoo.getString("EXCEL_TAG")).append("','").append(rsoo.getString("EXCEL_TAG2")).append("','").append(rsoo.getString("EXCEL_TAG3")).append("','").append(rsoo.getString("EXCEL_TAG4")).append("','").append(rsoo.getString("DESIGN_MODULE_TAG")).append("','").append(rsoo.getString("DESIGN_PROCEDURE_TAG")).append("','").append(rsoo.getString("DESIGN_CELL_TAG")).append("','").append(rsoo.getString("RECOMMEND_PROVIDER_TAG")).append("','").append(rsoo.getString("PRICE_CHANGE_TAG")).append("','").append(rsoo.getString("PRICE_ALARM_TAG")).append("','").append(rsoo.getString("promotion")).append("','").append(rsoo.getString("opinion")).append("','").append(rsoo.getString("promotion2")).append("','").append(rsoo.getString("opinion2")).append("','").append(rsoo.getString("promotion3")).append("','").append(rsoo.getString("opinion3")).append("','").append(rsoo.getString("promotion4")).append("','").append(rsoo.getString("opinion4")).append("')").toString();
							design_db.executeUpdate(sqll);
						}
						List rsList = GetWorkflow.getList(design_db, "design_config_workflow", "02");
						if (rsList.size() == 0)
						{
							String sql = (new StringBuilder("update design_file set product_name='")).append(product_name).append("',factory_name='").append(factory_name).append("',product_class='").append(product_class).append("',type='").append(type).append("',twin_name='").append(twin_name).append("',twin_ID='").append(twin_ID).append("',personal_unit='").append(personal_unit).append("',personal_value='").append(personal_value).append("',warranty='").append(warranty).append("',lifecycle='").append(lifecycle).append("',product_nick='").append(product_nick).append("',list_price='").append(list_price).append("',cost_price='").append(cost_price).append("',product_describe='").append(product_describe).append("',responsible_person_name='").append(responsible_person_name).append("',responsible_person_ID='").append(responsible_person_ID).append("',amount_unit='").append(amount_unit).append("',changer_ID='").append(changer_ID).append("',changer='").append(changer).append("',change_time='").append(change_time).append("',lately_change_time='").append(lately_change_time).append("',file_change_amount='").append(change_amount).append("',price_change_tag='0',check_tag='1' where product_ID='").append(product_ID).append("'").toString();
							design_db.executeUpdate(sql);
							String sql4 = (new StringBuilder("select * from design_module_details where product_ID='")).append(product_ID).append("'").toString();
							String sql1;
							for (ResultSet rs4 = design_db.executeQuery(sql4); rs4.next(); design_db1.executeUpdate(sql1))
							{
								double subtotal1 = Double.parseDouble(cost_price) * rs4.getDouble("amount");
								double subtotal3 = subtotal1 - rs4.getDouble("subtotal");
								String sql6 = (new StringBuilder("select * from design_module where design_ID='")).append(rs4.getString("design_ID")).append("'").toString();
								ResultSet rs6 = design_db1.executeQuery(sql6);
								if (rs6.next())
								{
									double subtotal5 = rs6.getDouble("cost_price_sum") + subtotal3;
									String sql8 = (new StringBuilder("update design_module set cost_price_sum='")).append(subtotal5).append("' where design_ID='").append(rs4.getString("design_ID")).append("'").toString();
									design_db1.executeUpdate(sql8);
								}
								sql1 = (new StringBuilder("update design_module_details set cost_price='")).append(cost_price).append("',subtotal='").append(subtotal1).append("' where product_ID='").append(product_ID).append("'").toString();
							}

							String sql5 = (new StringBuilder("select * from manufacture_design_procedure_module_details where product_ID='")).append(product_ID).append("'").toString();
							ResultSet rs5 = manufacture_db.executeQuery(sql5);
							if (rs5.next())
							{
								double subtotal2 = Double.parseDouble(cost_price) * rs5.getDouble("amount");
								double subtotal4 = subtotal2 - rs5.getDouble("subtotal");
								String sql7 = (new StringBuilder("select * from manufacture_design_procedure_details where design_ID='")).append(rs5.getString("design_ID")).append("' and procedure_name='").append(rs5.getString("procedure_name")).append("'").toString();
								ResultSet rs7 = manufacture_db1.executeQuery(sql7);
								if (rs7.next())
								{
									double subtotal6 = rs7.getDouble("module_subtotal") + subtotal4;
									String sql9 = (new StringBuilder("update manufacture_design_procedure_details set module_subtotal='")).append(subtotal6).append("' where design_ID='").append(rs5.getString("design_ID")).append("' and procedure_name='").append(rs5.getString("procedure_name")).append("'").toString();
									manufacture_db1.executeUpdate(sql9);
								}
								String sql11 = (new StringBuilder("select * from manufacture_design_procedure where design_ID='")).append(rs5.getString("design_ID")).append("'").toString();
								ResultSet rs11 = manufacture_db1.executeQuery(sql11);
								if (rs11.next())
								{
									double subtotal8 = rs11.getDouble("module_cost_price_sum") + subtotal4;
									String sql13 = (new StringBuilder("update manufacture_design_procedure set module_cost_price_sum='")).append(subtotal8).append("' where design_ID='").append(rs5.getString("design_ID")).append("'").toString();
									manufacture_db1.executeUpdate(sql13);
								}
								String sql3 = (new StringBuilder("update manufacture_design_procedure_module_details set cost_price='")).append(cost_price).append("',subtotal='").append(subtotal2).append("' where product_ID='").append(product_ID).append("'").toString();
								manufacture_db1.executeUpdate(sql3);
							}
						} else
						{
							String sql = (new StringBuilder("update design_file set product_name='")).append(product_name).append("',factory_name='").append(factory_name).append("',product_class='").append(product_class).append("',type='").append(type).append("',twin_name='").append(twin_name).append("',twin_ID='").append(twin_ID).append("',personal_unit='").append(personal_unit).append("',personal_value='").append(personal_value).append("',warranty='").append(warranty).append("',lifecycle='").append(lifecycle).append("',product_nick='").append(product_nick).append("',list_price='").append(list_price).append("',cost_price='").append(cost_price).append("',product_describe='").append(product_describe).append("',responsible_person_name='").append(responsible_person_name).append("',responsible_person_ID='").append(responsible_person_ID).append("',amount_unit='").append(amount_unit).append("',changer_ID='").append(changer_ID).append("',changer='").append(changer).append("',change_time='").append(change_time).append("',lately_change_time='").append(lately_change_time).append("',file_change_amount='").append(change_amount).append("',price_change_tag='1' where product_ID='").append(product_ID).append("'").toString();
							design_db.executeUpdate(sql);
							for (Iterator ite = rsList.iterator(); ite.hasNext(); design_db.executeUpdate(sql))
							{
								String elem[] = (String[])ite.next();
								sql = (new StringBuilder("insert into design_workflow(config_id,object_ID,describe1,describe2,type_id) values ('")).append(elem[0]).append("','").append(product_ID).append("','").append(elem[1]).append("','").append(elem[2]).append("','02')").toString();
							}

						}
					}
					catch (Exception ex)
					{
						ex.printStackTrace();
					}
					response.sendRedirect("design/price_change/register_ok_a.jsp");
				} else
				{
					response.sendRedirect((new StringBuilder("design/price_change/register_ok_c.jsp?product_ID=")).append(product_ID).toString());
				}
				design_db.commit();
				design_db1.commit();
				manufacture_db.commit();
				manufacture_db1.commit();
				design_db.close();
				design_db1.close();
				manufacture_db.close();
				manufacture_db1.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
